Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support bberg lookups #37

Merged
merged 8 commits into from
Jan 9, 2024
Merged

feat: support bberg lookups #37

merged 8 commits into from
Jan 9, 2024

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Jan 5, 2024

see AztecProtocol/aztec-packages#3880 for implementation example

Lookups allow us to assert that values in a set of columns equal some values in another set of columns.

This approach uses the log derivative method to perform lookups, where the lookup relation requires four extra columns ( as well as the read and write columns ) to function.

  • One selector column to initiate adding a value into the READ side of the lookup table ( lhs in pil )
  • One selector column to initiate adding a value into the WRITE side of the lookup table ( rhs in pil ) - { adding to the table }
  • One selector column to compute inverses - ( helper column )
  • One column to store the number of times a WRITE term is read - ( helper column )

The selector columns will need to be defined manually - as in the ToyAvm example.
The inverse column and the counts columns are automatically included by the code gen. ( this means there are two extra columns per lookup ( which is a little bit inefficient; but will do for now ).

The name of the inverse column is decided by the attribute tag #[attribute] above the lookup - which is required.
The name of the counts column is ${attribute}_counts.

Note: that in the circuit builder you are currently required to set the counts column value manually.

syntax:

  #[lookup_xor] // attribute
    q_xor { xor_a, xor_b, xor_c } in q_xor_table { table_xor_a, table_xor_b, table_xor_c };
    // lhs selector, lhs columns        // rhs selector, rhs columns

Copy link
Collaborator

@jeanmon jeanmon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work! Please address/look at my feedback before merging.

return false;
}}",
permutation_name = permutation_name
lookup_name = lookup_name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I would prefer two different identifiers, unless this is Rust standard practice.

Copy link
Member Author

@Maddiaa0 Maddiaa0 Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be replaced with the single identifier, as it is just for string templating - will edit

}

#[derive(Debug)]
/// PermSide
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste leftover? Probably should be "LookupSide"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually good point here- they are more or less the same i can unify the type

Copy link
Member Author

@Maddiaa0 Maddiaa0 Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually i probably wont, even though it is repeated it is much more readable when they are defined beside each other

bberg/src/lookup_builder.rs Outdated Show resolved Hide resolved
) -> Vec<Lookup>;
}

impl LookupBuilder for BBFiles {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this function and subsequent ones, replace variables like "perm", "perm_settings" by "lookup", "lookup_settings".

*
* @details To create your own lookup:
* 1) Create a copy of this class and rename it
* 2) Update all the values with the ones needed for your permutation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 2) Update all the values with the ones needed for your permutation
* 2) Update all the values with the ones needed for your lookup

static constexpr size_t READ_TERM_TYPES[READ_TERMS] = {read_term_types};

/**
* @brief They type of WRITE_TERM used for each write index
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @brief They type of WRITE_TERM used for each write index
* @brief The type of WRITE_TERM used for each write index

}}")
}

fn get_perm_side<F: FieldElement>(def: &SelectedExpressions<AlgebraicExpression<F>>) -> LookupSide {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename function to "get_lookup_side"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I shall unify these

{compute_inverse_exists}

/**
* @brief Get all the entities for the lookup when need to update them
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @brief Get all the entities for the lookup when need to update them
* @brief Get all the entities for the lookup when we need to update them

bberg/src/lookup_builder.rs Outdated Show resolved Hide resolved
@Maddiaa0 Maddiaa0 changed the title feat: support lookups feat: support bberg lookups Jan 9, 2024
@Maddiaa0 Maddiaa0 merged commit 5ed8dc7 into avm Jan 9, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants